﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace Abs.App.Admin
{
    public partial class Manage_Appointments : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //Kicks the non admin accounts out
            if (Session["Role"] == null)
                Response.Redirect("/User/Unauthorized_Access.aspx");
            if ((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.User)
                Response.Redirect("/User/Unauthorized_Access.aspx");
        }

        protected void datepicker_TextChanged(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (datepicker.Text == "")
            {
                return;
            }
            var appointmanager = Abs.Core.Management.Manage.Appointment;
            var appList = appointmanager.GetAppointmentsOnDate(datepicker.Text);
            
            foreach (var appointment in appList)
            {
                TableRow row = new TableRow();
                for (int i = 0; i < 7; i++)
                {
                    TableCell cell = new TableCell();
                    if (i == 0)
                    {
                        Label label = new Label();
                        label.Text = appointment.Room.Name;
                        cell.Controls.Add(label);
                    }
                    else if (i == 1)
                    {
                        Label label = new Label();
                        label.Text = appointment.User.Name;
                        cell.Controls.Add(label);
                    }
                    else if (i == 2)
                    {
                        Label label = new Label();
                        label.Text = appointment.StartTime.ToShortDateString();
                        cell.Controls.Add(label);
                    }
                    else if (i == 3)
                    {
                        Label label = new Label();
                        label.Text = appointment.StartTime.ToShortTimeString();
                        cell.Controls.Add(label);
                    }
                    else if (i == 4)
                    {
                        Label label = new Label();
                        label.Text = appointment.EndTime.ToShortTimeString();
                        cell.Controls.Add(label);
                    }
                    else if (i == 5)
                    {
                        HyperLink link = new HyperLink();
                        link.Text = "View Details";
                        link.NavigateUrl = "~/Admin/Appointment_Details.aspx?Id=" + appointment.AppointmentId.ToString();
                        cell.Controls.Add(link);
                    }
                    else if (i == 6)
                    {
                        HyperLink link = new HyperLink();
                        link.Text = "Delete Appointment";
                        link.NavigateUrl = "~/Admin/Delete_Appointment.aspx?Id=" + appointment.AppointmentId.ToString();
                        cell.Controls.Add(link);
                    }
                    row.Controls.Add(cell);
                }
                Table_Display.Controls.Add(row);
            }
   
        }
        
        
    }
}